# -coding:utf-8 -*-
"""
ctr 数据的相关处理
"""
import datetime
import common.dataFrame as df
import common.sql as db_sql
import pandas as pd


def ctr_result_handler(data_res, index_=None, *agrs, **kwargs):
    if index_ is None:
        print("请填写指标参数")
        exit()
    if(data_res.ErrorCode != 0):
        print("request ctr Error, ", data_res.ErrorMsg)
    else:
        print("ctr======分割线======")
        if index_ == "InstStatisticsInfo":
            _handler_InstStatisticsInfo(data_res=data_res,
                                        tb_name_="ctr_inststatisticsinfo", to_sql=1)
        elif(index_ == "InstHolderDetailInfo"):
            _handler_InstHolderDetailInfo(
                data_res=data_res, tb_name_='ctr_instholderdetailinfo', to_sql=1)
        elif(index_ == "InstHolderInfo"):
            _handler_InstHolderInfo(
                data_res=data_res, tb_name_='ctr_instholderinfo', to_sql=1)

        elif(index_ == "InstHolderTypeDetailInfo"):
            _handler_InstHolderTypeDetailInfo(
                data_res=data_res, tb_name_='ctr_instholdertypedetailinfo', to_sql=1)
        elif(index_ == "InstHolderTypeInfo"):
            _handler_InstHolderTypeInfo(
                data_res=data_res, tb_name_="ctr_instholdertypeinfo", to_sql=1)
        elif(index_ == "HKInstHoldingDetailInfo"):
            pass
        elif(index_ == "SaleStatisticInfo"):
            pass
        elif(index_ == "StockTradingInfo"):
            pass
        elif(index_ == "StockInfo"):
            pass
        elif(index_ == "HoldTradeDetailInfo"):
            pass
        elif(index_ == "QuotaSHSZHKInfo"):
            _handler_QuotaSHSZHKInfo(
                data_res=data_res, tb_name_="ctr_quotashszhkinfo", to_sql=1)
        elif(index_ == "DailyQuotaSHSZHKInfo"):
            _handler_DailyQuotaSHSZHKInfo(
                data_res=data_res, tb_name_="ctr_dailyquotashszhkinfo", to_sql=1)
        elif(index_ == "DailyTransSHSZHKInfo"):
            _handler_DailyTransSHSZHKInfo(
                data_res=data_res, tb_name_="ctr_dailytransshszhkinfo", to_sql=1)
        elif(index_ == "TransactionSHHKInfo"):
            _handler_TransactionSHHKInfo(
                data_res=data_res, tb_name_="ctr_transactionshhkinfo", to_sql=1)
        elif(index_ == "ActiveStockTOP10SHInfo"):
            _handler_ActiveStockTOP10SHInfo(
                data_res=data_res, tb_name_="ctr_activestocktop10shinfo", to_sql=1)
        elif(index_ == "ActiveStockTOP10SHHKInfo"):
            _handler_ActiveStockTOP10SHHKInfo(
                data_res=data_res, tb_name_="ctr_activestocktop10shhkinfo", to_sql=1)
        elif(index_ == "TransactionSZHKInfo"):
            _handler_TransactionSZHKInfo(
                data_res=data_res, tb_name_="ctr_transactionszhkinfo", to_sql=1)
        elif(index_ == "ActiveStockTOP10SZInfo"):
            _handler_ActiveStockTOP10SZInfo(
                data_res=data_res, tb_name_="ctr_activestocktop10szinfo", to_sql=1)
        elif(index_ == "ActiveStockTOP10SZHKInfo"):
            _handler_ActiveStockTOP10SZHKInfo(
                data_res=data_res, tb_name_="ctr_activestocktop10szhkinfo", to_sql=1)

        else:
            pass


def _handler_ActiveStockTOP10SZHKInfo(data_res, tb_name_=None, to_sql=None):
    """
    专题报表-沪深股票-沪深港通-深港股通十大活跃成交股

    """
    if to_sql is None:
        print("请填写tosql参数")
    else:
        df2 = pd.DataFrame()
        pddata2 = df.dict_convert_dataframe(
            dict=data_res.Data, label=data_res.Indicators, df=df2)
        db_sql.dataframe_tosql(pd_data2=pddata2, table_name=tb_name_)


def _handler_ActiveStockTOP10SZInfo(data_res, tb_name_=None, to_sql=None):
    """
    专题报表-沪深股票-沪深港通-深股通十大活跃成交股

    """
    if to_sql is None:
        print("请填写tosql参数")
    else:
        df2 = pd.DataFrame()
        pddata2 = df.dict_convert_dataframe(
            dict=data_res.Data, label=data_res.Indicators, df=df2)
        db_sql.dataframe_tosql(pd_data2=pddata2, table_name=tb_name_)


def _handler_TransactionSZHKInfo(data_res, tb_name_=None, to_sql=None):
    """
    专题报表-沪深股票-沪深港通-深港通成交统计表

    """
    if to_sql is None:
        print("请填写tosql参数")
    else:
        df2 = pd.DataFrame()
        pddata2 = df.dict_convert_dataframe(
            dict=data_res.Data, label=data_res.Indicators, df=df2)
        db_sql.dataframe_tosql(pd_data2=pddata2, table_name=tb_name_)


def _handler_ActiveStockTOP10SHHKInfo(data_res, tb_name_=None, to_sql=None):
    """
    专题报表-沪深股票-沪深港通-沪港股通十大活跃成交股

    """
    if to_sql is None:
        print("请填写tosql参数")
    else:
        df2 = pd.DataFrame()
        pddata2 = df.dict_convert_dataframe(
            dict=data_res.Data, label=data_res.Indicators, df=df2)
        db_sql.dataframe_tosql(pd_data2=pddata2, table_name=tb_name_)


def _handler_ActiveStockTOP10SHInfo(data_res, tb_name_=None, to_sql=None):
    """
    专题报表-沪深股票-沪深港通-沪股通十大活跃成交股

    """
    if to_sql is None:
        print("请填写tosql参数")
    else:
        df2 = pd.DataFrame()
        pddata2 = df.dict_convert_dataframe(
            dict=data_res.Data, label=data_res.Indicators, df=df2)
        db_sql.dataframe_tosql(pd_data2=pddata2, table_name=tb_name_)


def _handler_TransactionSHHKInfo(data_res, tb_name_=None, to_sql=None):
    """
    专题报表-沪深股票-沪深港通-沪港通成交统计表

    """
    if to_sql is None:
        print("请填写tosql参数")
    else:
        df2 = pd.DataFrame()
        pddata2 = df.dict_convert_dataframe(
            dict=data_res.Data, label=data_res.Indicators, df=df2)
        db_sql.dataframe_tosql(pd_data2=pddata2, table_name=tb_name_)


def _handler_DailyTransSHSZHKInfo(data_res, tb_name_=None, to_sql=None):
    """
    专题报表-沪深股票-沪深港通-沪深港通每日成交明细表

    """
    if to_sql is None:
        print("请填写tosql参数")
    else:
        df2 = pd.DataFrame()
        pddata2 = df.dict_convert_dataframe(
            dict=data_res.Data, label=data_res.Indicators, df=df2)
        db_sql.dataframe_tosql(pd_data2=pddata2, table_name=tb_name_)


def _handler_DailyQuotaSHSZHKInfo(data_res, tb_name_=None, to_sql=None):
    """
    专题报表-沪深股票-沪深港通-沪深港通每日额度明细表

    """
    if to_sql is None:
        print("请填写tosql参数")
    else:
        df2 = pd.DataFrame()
        pddata2 = df.dict_convert_dataframe(
            dict=data_res.Data, label=data_res.Indicators, df=df2)
        db_sql.dataframe_tosql(pd_data2=pddata2, table_name=tb_name_)


def _handler_QuotaSHSZHKInfo(data_res, tb_name_=None, to_sql=None):
    """
    专题报表-沪深股票-沪深港通-沪深港通额度信息统计表

    """
    if to_sql is None:
        print("请填写tosql参数")
    else:
        df2 = pd.DataFrame()
        pddata2 = df.dict_convert_dataframe(
            dict=data_res.Data, label=data_res.Indicators, df=df2)
        db_sql.dataframe_tosql(pd_data2=pddata2, table_name=tb_name_)


def _handler_HoldTradeDetailInfo(data_res, tb_name_=None, to_sql=None):
    """
    专题报表-沪深股票-重要持股人-重要股东二级市场交易明细表
    TODO
    """
    if to_sql is None:
        print("请填写tosql参数")
    else:
        df2 = pd.DataFrame()
        pddata2 = df.dict_convert_dataframe(
            dict=data_res.Data, label=data_res.Indicators, df=df2)
        db_sql.dataframe_tosql(pd_data2=pddata2, table_name=tb_name_)


def _handler_StockInfo(data_res, tb_name_=None, to_sql=None):
    """
    专题报表-沪深股票-龙虎榜-个股交易公开信息表
    TODO
    """
    if to_sql is None:
        print("请填写tosql参数")
    else:
        df2 = pd.DataFrame()
        pddata2 = df.dict_convert_dataframe(
            dict=data_res.Data, label=data_res.Indicators, df=df2)
        db_sql.dataframe_tosql(pd_data2=pddata2, table_name=tb_name_)


def _handler_StockTradingInfo(data_res, tb_name_=None, to_sql=None):
    """
    专题报表-沪深股票-龙虎榜-买卖交易前5名
    TODO
    """
    if to_sql is None:
        print("请填写tosql参数")
    else:
        df2 = pd.DataFrame()
        pddata2 = df.dict_convert_dataframe(
            dict=data_res.Data, label=data_res.Indicators, df=df2)
        db_sql.dataframe_tosql(pd_data2=pddata2, table_name=tb_name_)


def _handler_SaleStatisticInfo(data_res, tb_name_=None, to_sql=None):
    """
    专题报表-沪深股票-龙虎榜-营业交易统计表
    TODO
    """
    if to_sql is None:
        print("请填写tosql参数")
    else:
        df2 = pd.DataFrame()
        pddata2 = df.dict_convert_dataframe(
            dict=data_res.Data, label=data_res.Indicators, df=df2)
        db_sql.dataframe_tosql(pd_data2=pddata2, table_name=tb_name_)


def _handler_HKInstHoldingDetailInfo(data_res, tb_name_=None, to_sql=None):
    """
    专题报表-沪深股票-沪深港通-沪深股通标的港股机构持股明细
    TODO
    """
    if to_sql is None:
        print("请填写tosql参数")
    else:
        df2 = pd.DataFrame()
        pddata2 = df.dict_convert_dataframe(
            dict=data_res.Data, label=data_res.Indicators, df=df2)
        db_sql.dataframe_tosql(pd_data2=pddata2, table_name=tb_name_)


def _handler_InstHolderTypeInfo(data_res, tb_name_=None, to_sql=None):
    """
    专题报表-沪深股票-机构持股-机构持股汇总表（按品种）

    """
    if to_sql is None:
        print("请填写tosql参数")
    else:
        df2 = pd.DataFrame()
        pddata2 = df.dict_convert_dataframe(
            dict=data_res.Data, label=data_res.Indicators, df=df2)
        db_sql.dataframe_tosql(pd_data2=pddata2, table_name=tb_name_)


def _handler_InstHolderTypeDetailInfo(data_res, tb_name_=None, to_sql=None):
    """
    专题报表-沪深股票-机构持股-机构持股明细表（按品种）

    """
    if to_sql is None:
        print("请填写tosql参数")
    else:
        df2 = pd.DataFrame()
        pddata2 = df.dict_convert_dataframe(
            dict=data_res.Data, label=data_res.Indicators, df=df2)
        db_sql.dataframe_tosql(pd_data2=pddata2, table_name=tb_name_)


def _handler_InstHolderInfo(data_res, tb_name_=None, to_sql=None):
    """
    专题报表-沪深股票-机构持股-机构持股汇总表（按机构）

    """
    if to_sql is None:
        print("请填写tosql参数")
    else:
        df2 = pd.DataFrame()
        pddata2 = df.dict_convert_dataframe(
            dict=data_res.Data, label=data_res.Indicators, df=df2)
        db_sql.dataframe_tosql(pd_data2=pddata2, table_name=tb_name_)


def _handler_InstHolderDetailInfo(data_res, tb_name_=None, to_sql=None):
    """
    专题报表-沪深股票-机构持股-机构持股明细表（按机构)
    处理数据

    """
    if to_sql is None:
        print("请填写tosql参数")
    else:
        df2 = pd.DataFrame()
        pddata2 = df.dict_convert_dataframe(
            dict=data_res.Data, label=data_res.Indicators, df=df2)
        db_sql.dataframe_tosql(pd_data2=pddata2, table_name=tb_name_)


def _handler_InstStatisticsInfo(data_res, tb_name_=None, to_sql=None):
    """
    专题报表-沪深股票-机构持股-机构类型统计表（按机构）
    处理数据
    """
    if to_sql is None:
        print("请填写tosql参数")
    else:
        df2 = pd.DataFrame()
        pddata2 = df.dict_convert_dataframe(
            dict=data_res.Data, label=data_res.Indicators, df=df2)
        db_sql.dataframe_tosql(pd_data2=pddata2, table_name=tb_name_)


if __name__ == "__main__":
    pass
